home *** CD-ROM | disk | FTP | other *** search
/ Windows News 2010 Summer - Disc 1 / WN_Ete2010_CD1.iso / Onglet5 / Weezo / Weezo setup.exe / {code_appDir} / www / local / serverAccess.php < prev    next >
PHP Script  |  2010-05-19  |  10KB  |  288 lines

  1. <?php
  2. /**
  3.  * Application and server connection test
  4.  *
  5.  *
  6.  * PHP version 5
  7.  *
  8.  * LICENSE: This source file is subject to version 3.0 of the PHP license
  9.  * that is available through the world-wide-web at the following URI:
  10.  * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
  11.  * the PHP License and are unable to obtain it through the web, please
  12.  * send a note to license@php.net so we can mail you a copy immediately.
  13.  *
  14.  * @category   NA
  15.  * @package    NA
  16.  * @author     Nicolas Bruley / Peer 2 World <contact@weezo.net>
  17.  * @copyright  2005-2009 Nicolas Bruley / Peer 2 World
  18.  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  19.  * @version    CVS: $Id:$
  20.  * @link       http://www.weezo.net
  21.  * @since      File available since Release 1.0.0
  22.  */
  23.  
  24. // Initialize script data
  25. require_once('localFunctions.php');
  26. lfInit();
  27.  
  28. $steps=array(0=>array('icon'=>'ok'),1=>array('icon'=>'v'),2=>array('icon'=>'v'));
  29.  
  30. if(!isset($_GET['step']) && !isset($_POST['step'])) die('missing argument');
  31. if(isset($_POST['step'])) $step=$_POST['step']; else $step=$_GET['step'];
  32. if(isset($_POST['silent'])) $_GET['silent']=$_POST['silent'];
  33.  
  34. // APPLICATION OUT ERROR
  35. if($step=='appOutError'){
  36.     $steps[0]['icon']='alert';
  37.     $steps[0]['message']=cfCaption('accessTestAppNok');
  38.     $steps[0]['messageType']='error';
  39.  
  40.     $steps[1]['message']=cfCaption('accessNotTested');
  41.     $steps[2]['message']=cfCaption('accessNotTested');
  42.  
  43.     $leftIcon='alertBig';
  44.     $leftMessage=cfCaption('genError');
  45.  
  46.     $button1=outButton(cfCaption('genRetry'),'close:restart',outIcon('go'));
  47.     $button2=outButton(cfCaption('genAbandon'),'javascript:wl.UICommand(\'close\')',outIcon('cancel'));
  48.  
  49.     $error=true;
  50. }
  51.  
  52. // APPLICATION OUT OK
  53. elseif($step=='appOutOk'){
  54.     $steps[0]['icon']='ok';
  55.     $steps[0]['message']='<b>'.cfCaption('genOK').'</b>';
  56.     $steps[0]['messageType']='ok';
  57.  
  58.     $steps[1]['icon']='go';
  59.     $steps[1]['message']=cfCaption('accessTesting');
  60.     $steps[1]['messageType']='progress';
  61.  
  62.     $steps[2]['message']=cfCaption('accessNotTested');
  63.  
  64.     $leftIcon='loadingBig';
  65.     $leftMessage=cfCaption('accessTesting');
  66.     $nextStep='serverOutTest';
  67.  
  68.     $button1=outButton(cfCaption('genAbandon'),'javascript:wl.UICommand(\'close\')',outIcon('cancel'));
  69. }
  70. elseif($step=='serverOutTest'){
  71.     // Check outgoing server connection by opening a socket and HTTP connection to weezo.net server
  72.     cfAsyncHeader();
  73.     if (cfSocketHTTPRequest(DNS_SITE.'/portCheck.php')){
  74.         echo cfAsyncXMLJSaction('document.location="/local/serverAccess.php?step=serverOutOk&silent='.((@$_GET['silent'])?1:0).'";');
  75.     }
  76.     else{
  77.         echo cfAsyncXMLJSaction('document.location="/local/serverAccess.php?step=serverOutError&silent='.((@$_GET['silent'])?1:0).'";');
  78.     }
  79.     echo cfAsyncFooter();
  80.     exit;
  81. }
  82.  
  83. // SERVER OUT OK
  84. elseif($step=='serverOutOk'){
  85.     $steps[0]['icon']='ok';
  86.     $steps[0]['message']='<b>'.cfCaption('genOK').'</b>';
  87.     $steps[0]['messageType']='ok';
  88.  
  89.     $steps[1]['icon']='ok';
  90.     $steps[1]['message']='<b>'.cfCaption('genOK').'</b>';
  91.     $steps[1]['messageType']='ok';
  92.  
  93.     if(cfGGetVar('serverPort')<80){
  94.         $steps[2]['icon']='unknown';
  95.         $steps[2]['message']=cfCaption('startPortsTested','<b>'.cfGGetVar('serverPort').'</b>');
  96.         $steps[2]['messageType']='error';
  97.  
  98.         $leftIcon='unknownBig';
  99.         $leftMessage=cfCaption('accessNotTested');
  100.  
  101.         $button1=outButton(cfCaption('genOK'),'javascript:wl.UICommand(\'close\')',outIcon('ok'));
  102.     }
  103.     else{
  104.         $steps[2]['icon']='go';
  105.         $steps[2]['message']=cfCaption('accessTesting');
  106.  
  107.         $leftIcon='loadingBig';
  108.         $leftMessage=cfCaption('accessTesting');
  109.  
  110.         $nextStep='serverInTest';
  111.  
  112.         $button1=outButton(cfCaption('genAbandon'),'javascript:wl.UICommand(\'close\')',outIcon('cancel'));
  113.     }
  114. }
  115.  
  116. // SERVER OUT ERROR
  117. elseif($step=='serverOutError'){
  118.     $steps[0]['icon']='ok';
  119.     $steps[0]['message']='<b>'.cfCaption('genOK').'</b>';
  120.     $steps[0]['messageType']='ok';
  121.  
  122.     $steps[1]['icon']='alert';
  123.     $steps[1]['message']=cfCaption('accessTestHttpdOutNok');
  124.     $steps[1]['messageType']='error';
  125.  
  126.     $steps[2]['message']=cfCaption('accessNotTested');
  127.  
  128.     $leftIcon='alertBig';
  129.     $leftMessage=cfCaption('genError');
  130.  
  131.     $button1=outButton(cfCaption('genRetry'),'javascript:reload(\'appOutOk\')',outIcon('go'));
  132.     $button2=outButton(cfCaption('genAbandon'),'javascript:wl.UICommand(\'close\')',outIcon('cancel'));
  133.  
  134.     $error=true;
  135. }
  136.  
  137. // SERVER IN
  138. elseif($step=='serverInTest'){
  139.     $data=cfSocketHTTPRequest(DNS_SITE.'/portCheck.php?lng=en&port='.cfGGetVar('serverPort').'&v='.cfGGetVar('appVersion'));
  140.  
  141.     cfAsyncHeader();
  142.     if(strpos($data,'RESULT=OK')!==false) {
  143.         // Check for wrong LAN IP found by weezo.net server
  144.         if(strpos($data,'LANIP=')!==false && strpos($data,'LANIP='.cfGGetVar('LANIPComputed'))===false)
  145.             echo cfAsyncXMLJSaction('document.location="/local/serverAccess.php?step=serverInError&silent='.((@$_GET['silent'])?1:0).'";');
  146.         // All OK
  147.         else
  148.             echo cfAsyncXMLJSaction('document.location="/local/serverAccess.php?step=serverInOk&silent='.((@$_GET['silent'])?1:0).'";');
  149.     }
  150.     else echo cfAsyncXMLJSaction('document.location="/local/serverAccess.php?step=serverInError&silent='.((@$_GET['silent'])?1:0).'";');
  151.     echo cfAsyncFooter();
  152.     exit;
  153. }
  154.  
  155. // SERVER IN OK
  156. elseif($step=='serverInOk'){
  157.     $steps[0]['icon']='ok';
  158.     $steps[0]['message']='<b>'.cfCaption('genOK').'</b>';
  159.     $steps[0]['messageType']='ok';
  160.  
  161.     $steps[1]['icon']='ok';
  162.     $steps[1]['message']='<b>'.cfCaption('genOK').'</b>';
  163.     $steps[1]['messageType']='ok';
  164.  
  165.     $steps[2]['icon']='ok';
  166.     $steps[2]['message']='<b>'.cfCaption('genOK').'</b>';
  167.     $steps[2]['messageType']='ok';
  168.  
  169.     $leftIcon='okBig';
  170.     $leftMessage=cfCaption('genOK');
  171.  
  172.     $button2=outButton(cfCaption('genOK'),'javascript:wl.UICommand(\'close:ok\')',outIcon('ok'));
  173. }
  174.  
  175. // SERVER IN ERROR
  176. elseif($step=='serverInError'){
  177.     $steps[0]['icon']='ok';
  178.     $steps[0]['message']=cfCaption('genOK');
  179.     $steps[0]['messageType']='ok';
  180.  
  181.     $steps[1]['icon']='ok';
  182.     $steps[1]['message']=cfCaption('genOK');
  183.     $steps[1]['messageType']='ok';
  184.  
  185.     $steps[2]['icon']='alert';
  186.     $steps[2]['message']=cfCaption('accessTestHttpdInNok','<b>'.cfGGetVar('serverPort').'</b>');
  187.     $steps[2]['messageType']='error';
  188.  
  189.     $leftIcon='alertBig';
  190.     $leftMessage=cfCaption('genError');
  191.  
  192.     $button1=outButton(cfCaption('genRetry'),'javascript:reload(\'serverOutOk\')',outIcon('go'));
  193.     $button2=outButton(cfCaption('genAbandon'),'javascript:wl.UICommand(\'close\')',outIcon('cancel'));
  194.  
  195.     $error=true;
  196. }
  197.  
  198. /**
  199.  * Display page
  200.  */
  201. cfInsertHEAD(false);
  202. echo '<meta width="650x480"></meta>';
  203. echo '<meta title="Weezo - '.cfCaption('startTestServerAccess').'"></meta>';
  204. echo '</head>';
  205. echo '<body title="Weezo" width="650" height="480" oncontextmenu="return false;" '.((isset($nextStep))?'onload="window.setTimeout(\'goSubmit()\',500)" style="cursor:wait;">':'>');
  206. ?>
  207. <script type="text/javascript">
  208. function goSubmit(){
  209.     sendData("silent=<?php echo ((@$_GET['silent'])?1:0);?>&step="+document.forms.nextStep.step.value);
  210. }
  211. function reload(nStep){
  212.     window.location='<?php echo $_SERVER['PHP_SELF'];?>?step='+nStep+'&silent=<?php echo ((@$_GET['silent'])?1:0);?>';
  213. }
  214. function retry(nStep){
  215. <?php
  216. echo "document.body.style.cursor='wait';\n";
  217. echo 'document.forms.nextStep.step.value=nStep;';
  218. echo "goSubmit();";
  219. echo "\n}\n";
  220. echo "</script>\n";
  221. echo '<table class="frame1"><tr><td style="vertical-align:top; text-align:center; width:80px;padding-right:10px;height:100%">';
  222.  
  223. // Left icon
  224. echo '<div class="frame1Header">'.cfCaption('genStatus','').'</div><br/>';
  225. echo '<div style="border:1px solid #CCC;padding:7px; width:1px; margin-bottom:5px;">'.outImage(outIcon($leftIcon),false,'id="leftIcon"').'</div>';
  226. if($leftMessage==cfCaption('genError')) echo '<div class="warning" style="font-weight:bold">'; else echo '<div>';
  227. echo $leftMessage.'</div><br/><br/><br/>';
  228.  
  229. // UPnP information
  230. echo '<div style="border:1px solid #CCC;padding:7px;width:1px; margin-bottom:5px;">'.outImage(outIcon('UPnP'),false,false).'</div>';
  231. if(cfGGetVar('UPnPEnabled')){
  232.     echo '<div style="color:#2A2;font-weight:bold">'.cfCaption('genActivated').'</div>';
  233.     if(!cfGGetVar('UPnPMappingOK')) echo '<br/><span class="warning">'.outImage(outIcon('alert')).' '.cfCaption('UPnPFailed').'</span>';
  234.  
  235. }
  236. else{
  237.     echo '<span class="warning" style="font-weight:bold">'.cfCaption('genActivatedFalse').'</span>';
  238. }
  239. echo '</td><td>';
  240.  
  241.  
  242. // Right part
  243. echo '<div class="frame1Header">'.cfCaption('genStep','').'</div><br/>';
  244. for($i=0;$i<3;$i++){
  245.     echo outDivFrame('frame2',false,'width:540px');
  246.     echo '<div style="font-size:30px;float:left; margin-right:20px; margin-top:25px; padding-bottom:25px; margin-left:3px">'.($i+1).'. '.'</div>';
  247.     echo '<div class="frame2Header" style="width:100%;">'.outImage(outIcon($steps[$i]['icon']),false,false,'height:16px;width:16px;margin-right:7px;vertical-align:middle');
  248.     switch ($i) {
  249.         case 0:
  250.             echo cfCaption('accessTestAppOut');
  251.             echo outImage(outIcon('appOut'),false,false,'position:absolute;right:25px;');
  252.             break;
  253.         case 1:
  254.             echo cfCaption('accessTestHttpdOut');
  255.             echo outImage(outIcon('serverOut'),false,false,'position:absolute;right:25px;');
  256.             break;
  257.         case 2:
  258.             echo cfCaption('accessTestHttpdIn');
  259.             echo outImage(outIcon('serverIn'),false,false,'position:absolute;right:25px;');
  260.             break;
  261.     }
  262.     echo '</div>';
  263.     if(!isset($steps[$i]['messageType'])) echo '<div style="margin-left:79px;margin-top:3px">';
  264.     elseif($steps[$i]['messageType']=='error') echo '<div class="warning" style="margin-left:79px;margin-top:3px">';
  265.     elseif($steps[$i]['messageType']=='progress') echo '<div class="warning" style="color:#44F;margin-left:79px;margin-top:3px">';
  266.     elseif($steps[$i]['messageType']=='ok') echo '<div class="warning" style="color:#2C2;margin-left:79px;margin-top:3px">';
  267.     if(isset($steps[$i]['message'])) echo $steps[$i]['message']; else echo ' <br> ';
  268.     echo '</div></div></div><br/>';
  269. }
  270. echo '</td></tr></table>';
  271.  
  272. //if($buttons=='retryAppCancel') echo 1;
  273. echo '<center>';
  274. if(isset($button1)) echo $button1;
  275. if(isset($button2)) echo '<span style="width:30px"> </span>'.$button2;
  276. echo '</center>';
  277.  
  278. echo '<form name="nextStep" action="'.$_SERVER['PHP_SELF'].'" style="display:none"><input type="text" name="step" value="'.((isset($nextStep))?$nextStep:'').'"><input type="text" name="silent" value="'.((@$_GET['silent'])?1:0).'"></form>';
  279.  
  280. // If error, force form show (might have been launched hidden after an update)
  281. if(@$error){
  282.     echo "<script type=\"text/javascript\">wl.UICommand('show')</script>";
  283. }
  284. if($step=='serverInOk' && @$_GET['silent']){
  285.     echo "<script type=\"text/javascript\">wl.UICommand('close')</script>";
  286. }
  287. ?>
  288. </body></html>